package com.hongmeng.teamwork.factory.task;

import com.hongmeng.teamwork.entity.dto.TaskMessageDto;
import com.hongmeng.teamwork.entity.dto.TeamworkTaskDto;
import com.hongmeng.teamwork.entity.po.TeamworkTask;
import com.hongmeng.teamwork.enums.TaskOptTypeEnum;
import com.hongmeng.teamwork.enums.TaskStatusEnum;
import com.hongmeng.teamwork.tempalte.MessageSendTemplate;
import org.springframework.stereotype.Service;

/**
 * 任务更新状态处理器
 */
@Service
public class TaskUpdateStatusHandler implements TaskOptHandler {

    @Override
    public TaskOptTypeEnum getOptType() {
        return TaskOptTypeEnum.UPDATE_STATUS;
    }

    @Override
    public String buildMessage(TaskMessageDto taskMessageDto) {
        TeamworkTaskDto teamworkTaskDto = taskMessageDto.getTeamworkTaskDto();
        TeamworkTask teamworkTask = taskMessageDto.getTeamworkTask();
        return MessageSendTemplate.updateTaskTemplate(teamworkTaskDto.getUpdatedUser().getName(),
                teamworkTask.getName(),
                taskMessageDto.getProjectName(),
                taskMessageDto.getOldLeaderUser(),
                teamworkTask.getDescription(),
                TaskStatusEnum.ofEnum(teamworkTask.getStatus()),
                TaskStatusEnum.ofEnum(teamworkTaskDto.getStatus()));
    }
}
